import { Space, Tag } from "antd";
import { LibDescriptionProps } from "./data";
import { forwardRef, useState } from "react";

const LibDescription: React.FC<LibDescriptionProps> = (props, uploadRef) => {
  // const [props.checkedKeys, setprops.checkedKeys] = useState<React.Key[]>([]);
  const driveTypeMap = new Map([
    [1, 'V90'],
    [2, 'S210'],
  ]);

  const encoderMap = new Map([
    [0, '单圈绝对编码器'],
    [1, '多圈绝对编码器'],
    [2, '增量式编码器'],
  ]);

  const brakeMap = new Map([
    [0, '不带抱闸'],
    [1, '带抱闸'],
  ]);

  const loadTypeMap = new Map([
    [1, '水平'],
    [2, '旋转'],
    [3, '垂直'],
    [4, '斜坡'],
    [5, '其它'],
  ]);

  const mechanicalStructureMap = new Map([
    [1, '丝杠'],
    [2, '齿轮齿条'],
    [3, '皮带轮'],
    [4, '圆盘'],
    [5, '辊式带'],
    [6, '链条'],
    [7, '其它'],
  ]);

  const controlModeMap = new Map([
    [1, 'TO'],
    [2, 'Epos'],
    [3, 'Speed'],
  ]);

  const commTelegramMap = new Map([
    [105, '105'],
    [111, '111'],
    [102, '102'],
    [3, '3'],
    [1, '1'],
  ]);

  const additionalTelegramMap = new Map([
    [999, 'None'],
    [750, '750'],
  ]);

  const motorRotationMap = new Map([
    [0, '正向'],
    [1, '反向'],
  ]);

  const originalMap = new Map([
    [0, '来自设备管理'],
    [1, '其他'],
  ]);

  const diMap = new Map([
    [0, 'NA'],
    [2, 'RESET'],
    [3, 'CWL'],
    [4, 'CCWL'],
    [11, 'TLIM'],
    [20, 'SLIM'],
    [24, 'REF'],
    [29, 'EMGS'],
  ]);

  const doMap = new Map([
    [1, 'RDY'],
    [2, 'FAULT'],
    [3, 'INP'],
    [4, 'ZSP'],
    [6, 'TLR'],
    [8, 'MBR'],
    [9, 'OLL'],
    [12, 'REFOK'],
    [14, 'RDY_ON'],
    [15, 'STO'],
    [16, 'PZD1'],
    [17, 'PZD2'],
  ]);

  const modualActiveMap = new Map([
    [1, 'Yes'],
    [0, 'No'],
  ]);

  const pzdMap = new Map([
    [0, '无功能'],
    [1, '实际扭矩'],
    [2, '实际绝对电流'],
    [3, 'DI状态'],
  ]);

  return (
    <div>
      <div>
        <br></br>
      </div>

      <div>【基础信息配置】</div>
      <div>
        <Space size="middle">
          {'【轴名称】' + props.row.shaftName}
          {'【驱动类型】' + driveTypeMap.get(props.row.driveType)}
        </Space>
      </div>
      <div>
        <br></br>
      </div>
      <div>【电机配置数据】</div>
      <div>
        <Space size="middle">
          {'【电机ID】' + props.row.motorId}
          {'【编码器类型】' + encoderMap.get(props.row.ecoderType)}
          {'【抱闸配置 P1215】' + brakeMap.get(props.row.brake)}
          {'【额定电压 P304 [V]】' + props.row.ratedVoltage}
          {'【额定电流 P305 [A]】' + props.row.ratedCurrent}
          {'【额定功率 P307 [kW]】' + props.row.ratedPower}

        </Space>
        <Space size="middle">
          {'【额定速度 P311 [rpm]】' + props.row.ratedSpeed}
          {'【额定转矩 P312 [Nm]】' + props.row.ratedTorque}
          {'【电机转动惯量 P341 [kg.m2]】' + props.row.motorInertia}
          {/* {'【t [ms]】' + props.row.motorTime}
          {'【额定速度 [1/s]】' + props.row.ratedSecSpeed}
          
        </Space>
        <Space size="middle">
          {'【ω [rad/s]】' + props.row.angularVel}
          {'【角加速度a】' + props.row.angularAcc}
          {'【加速力矩Macc [Nm]】' + props.row.accMoment}
          {'【Macc/Me [%]】' + props.row.momentRatio} */}
        </Space>
      </div>
      <div>
        <br></br>
      </div>
      <div hidden={props.isEngineer}>【默认参数】</div>
      <div hidden={props.isEngineer}>
        <Space size="middle">
          {'【速度环增益默认Kp P29120 [Nms/rad]】' + props.row.kpDefault}
          {'【速度环积分默认Tn P29121 [ms]】' + props.row.tnDefault}
        </Space>
        <Space size="middle">
          {'【位置环增益默认 P29110 [1000/min]】' + props.row.kprDefault}
          {'【位置环滤波默认 P2533 [1000/min]】' + props.row.posFilterDefault}
        </Space>
      </div>
      <div>
        <br></br>
      </div>
      <div>【驱动配置】</div>
      <div>
        <Space size="middle">
          {'【负载类型】' + loadTypeMap.get(props.row.loadType)}
          {'【机械结构】' + mechanicalStructureMap.get(props.row.mechanicalStructure)}
          {'【控制报文 P922]】' + commTelegramMap.get(props.row.commTelegram)}
          {'【附加报文 P8864】' + additionalTelegramMap.get(props.row.additionalTelegram)}
          {'【控制模式】' + controlModeMap.get(props.row.controlMode)}
          {'【电机最大转速 P1082 [rpm]】' + props.row.velocityMax}
        </Space>
      </div>
      <div>
        <br></br>
      </div>
      <div>【工艺参数】</div>
      <div hidden={props.row.controlMode != 2}>【EPOS】</div>
      <div hidden={props.row.controlMode != 2}>
        <Space size="middle">
          {'【负载转速 (EPOS) P29248 [rpm]】' + props.row.gearRationLoad}
          {'【电机转速 (EPOS) P29249 [rpm]】' + props.row.gearRationMotor}
          {'【10mm对应的LU (EPOS)】' + props.row.positionAccuracy}
          {'【每转LU (EPOS) P29247】' + props.row.luLoopEpos}
        </Space>
        <Space size="middle">
          {'【位置环增益 (EPOS) P29110 [1000/min]】' + props.row.kprEpos}
          {'【位置环滤波 (EPOS) P2533 [1000/min]】' + props.row.posFilterEpos}
          {'【速度前馈系数 (EPOS) P29111 [%]】' + props.row.coeffVelEpos}
        </Space>
        <Space size="middle">
          {'【EPOS 最大速度 P2571 [1000LU/min]】' + 6 * props.row.vmaxEpos * props.row.positionAccuracy}
          {'【EPOS 最大加速度 P2572 [1000 LU/s²]】' + props.row.accmaxEpos}
          {'【EPOS 最大减速度 P2573 [1000 LU/s²]】' + props.row.dccmaxEpos}
        </Space>
        <Space size="middle">
          {'【EPOS 急动限制 P2574 [1000 LU/s³]】' + props.row.jerkEpos}
          {'【EPOS 急动限制激活 P2575】' + props.row.jerkActiveEpos}
        </Space>
      </div>
      <div hidden={props.row.controlMode != 3}>【Speed】</div>
      <div hidden={props.row.controlMode != 3}>
        <Space size="middle">
          {'【速度环增益Kp (Speed) V90 P29120 [Nms/rad] /S210 P1460】' + props.row.kpSpeed}
          {'【速度环积分时间Tn (Speed) V90 P29121 [ms] / S210 P1462】' + props.row.tnSpeed}
        </Space>
        <Space size="middle">
          {'【斜坡上升时间 (Speed) P1120 [s]】' + props.row.tincSpeed}
          {'【斜坡下降时间 (Speed) P1121 [s]】' + props.row.tdecSpeed}
        </Space>
        <Space size="middle">
          {'【斜坡圆弧起始时间 (Speed) P1130 [s]】' + props.row.tstartSpeed}
          {'【斜坡圆弧结束时间 (Speed) P1131 [s]】' + props.row.tstopSpeed}
        </Space>
      </div>

    </div>
  );
};

const DriveParaLibDescription = forwardRef<unknown, LibDescriptionProps>(LibDescription);

export default DriveParaLibDescription;